<template>
  <div>
    <div class="el-row--flex is-align-middle is-justify-space-between">
      <el-button size="small" @click="handleDelete">
        删除监控器类型
      </el-button>
      <el-button size="small" @click="$refs.NewMonitor.show()">
        添加新监控器类型
      </el-button>
    </div>
    <el-table
      class="mt10"
      :data="tableData"
      :header-cell-style="{ background: '#f5f5f5' }"
      size="mini"
    >
      <el-table-column label="选择" width="60">
        <template slot-scope="scope">
          <el-radio
            v-model="tableSelect"
            :label="scope.row.monitor_id"
            style="margin-left: 10px;"
            @change="getTemplateRow(scope.row.monitor_id)"
          >
            &nbsp;
          </el-radio>
        </template>
      </el-table-column>
      <el-table-column label="监控器类型ID" prop="monitor_id" />
      <el-table-column label="监控器类型名" prop="monitor_name" width="600" />
    </el-table>
    <div class="mt10 el-row--flex is-justify-end">
      <el-pagination
        background
        :current-page="page"
        layout="total, prev, pager, next"
        :page-size="limit"
        :page-sizes="[100, 200, 300, 400]"
        small
        :total="count"
        @current-change="handleCurrentChangePage"
      />
    </div>
    <new-monitor ref="NewMonitor" @change="loadingList" />
  </div>
</template>

<script>
import radioTable from "@/utils/mixin/radioTable";
import checkSelectTable from "@/utils/mixin/checkSelectTable";
import monitor from "@/api/recognize/monitor";
import NewMonitor from "@/views/visibility/toast/newMonitor";
export default {
  name: "Monitor",
  components: { NewMonitor },
  mixins: [radioTable, checkSelectTable],
  data: () => {
    return {
      tableData: [],
      limit: 20,
      page: 1,
      count: 0
    };
  },
  mounted() {
    this.loadingList();
  },
  methods: {
    handleDelete() {
      let data = {};
      this.is_check_table("monitor_id") &&
        (data = this.is_get_select_data()) &&
        monitor
          .del({
            monitor_id: data.monitor_id
          })
          .then(res => {
            this.$message.success(res.data.message);
            this.loadingList();
          });
    },
    async loadingList() {
      monitor
        .list({
          limit: this.limit,
          page: this.page
        })
        .then(res => {
          this.count = res.data.count;
          this.tableData = res.data.monitor_type;
        });
    },

    handleCurrentChangePage(val) {
      this.page = val;
      this.loadingList();
    }
  }
};
</script>

<style scoped></style>
